package com.k.kppcloud.consumer.controller;

import com.k.kppcloud.consumer.feign.HelloService;
import com.k.kppcloud.consumer.feign.HelloTwoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ConsumerHelloController {
    @Autowired
    private HelloService helloService;
    @Autowired
    private HelloTwoService helloTwoService;

    /**
     * 通过 feign 指定 name 调用服务,有负载.(需要 )
     * <dependency>
     *     <groupId>com.alibaba.cloud</groupId>
     *     <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
     *     <exclusions>
     *         <!-- 将ribbon排除 使用 spring-cloud-starter-loadbalancer -->
     *         <exclusion>
     *             <groupId>org.springframework.cloud</groupId>
     *             <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
     *         </exclusion>
     *     </exclusions>
     * </dependency>
     *
     * <dependency>
     *     <groupId>org.springframework.cloud</groupId>
     *     <artifactId>spring-cloud-starter-openfeign</artifactId>
     * </dependency>
     * 和
     * <dependency>
     *     <groupId>org.springframework.cloud</groupId>
     *     <artifactId>spring-cloud-starter-loadbalancer</artifactId>
     * </dependency>
     *
     * @return Result
     */
    @RequestMapping("/consumeHello")
    @ResponseBody
    public String consumeHello() {
        String hello = helloService.sayHello();
        System.out.println("consumer:consumeHello remote call sayHello result:"+hello);
        return hello;
    }

    /**
     * 通过 feign 指定 url 访问指定服务,无负载
     * @return Result
     */
    @RequestMapping("/consumeHelloTwo")
    @ResponseBody
    public String consumeHelloTwo() {
        String hello = helloTwoService.sayHello();
        System.out.println("consumer: consumeHelloTwo remote call sayHello result:"+hello);
        return hello;
    }
}
